package com.Nahida.NaHome.activity.settings;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.view.KeyEvent;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.Nahida.NaHome.R;
import com.Nahida.NaHome.activity.base.BaseActivity;
import com.Nahida.NaHome.util.MsgUtil;
import com.Nahida.NaHome.util.SharedPreferencesUtil;

public class SettingKeyActivity extends BaseActivity {

    TextView text_keycode;

    @SuppressLint("SetTextI18n")
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_setting_key);

        text_keycode = findViewById(R.id.text_keycode);
        text_keycode.setText("扫描键键值：" + SharedPreferencesUtil.getInt("scankey", 286));
    }

    @SuppressLint("SetTextI18n")
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if(text_keycode!=null && event.getAction() == KeyEvent.ACTION_DOWN) {
            if (keyCode != KeyEvent.KEYCODE_BACK && keyCode != KeyEvent.KEYCODE_HOME) {
                text_keycode.setText("扫描键键值："+keyCode);
                SharedPreferencesUtil.putInt("scankey", keyCode);
                MsgUtil.showMsg("获取到按键：" + keyCode, this);
            }
        }
        return super.onKeyDown(keyCode, event);
    }
}
